window.addEventListener('pywebviewready', async function() {
    await pywebview.api.init()

    var saveFolder = await pywebview.api.get_save_folder()
    document.getElementById('save-folder-input').value = saveFolder
})

async function select_folder(){
    var folder = await pywebview.api.select_folder()
    document.getElementById('save-folder-input').value = folder
}

function disable_write(){
    document.getElementById('save-folder-input').disabled = true
    document.getElementById('folder-selector').disabled = true
    document.getElementById('share-text-input').disabled = true
    document.getElementById('download_video-btn').disabled = true
}

function enable_write(){
    document.getElementById('save-folder-input').disabled = false
    document.getElementById('folder-selector').disabled = false
    document.getElementById('share-text-input').disabled = false
    document.getElementById('download_video-btn').disabled = false
}

async function download_video(){
    disable_write()
    var shareText = document.getElementById('share-text-input').value
    var saveFolder = document.getElementById('save-folder-input').value
    var convertSound = document.getElementById('convert-checker').checked
    var res = await pywebview.api.download_video(shareText, saveFolder, convertSound)

}

